#include<bits/stdc++.h>
using namespace std;
#define mkp make_pair
#define fir first
#define sec second
const int N = 1e6+5,lim = 1e6,INF = 0x3f3f3f3f;
int Q;
multiset< pair < int,int > >st1,st2;
char ch;
struct Node{
    int mn1,mn2,ans;
}tr[N<<2];
multiset<int>ts1[N],ts2[N];
#define lc c<<1
#define rc c<<1|1
#define mid (l+r>>1)
Node operator + (Node i,Node j){return Node{min(i.mn1,j.mn1),min(i.mn2,j.mn2),min(min(i.ans,j.ans),i.mn1+j.mn2)};}
void add1(int c,int l,int r,int x,int y)
{
    if(l == r)
    {
        ts1[l].insert(y);
        tr[c].mn1 = *ts1[l].begin();
        tr[c].ans = tr[c].mn1 + tr[c].mn2;
        return ;
    }
    if(x <= mid) add1(lc,l,mid,x,y);
    if(x > mid) add1(rc,mid+1,r,x,y);
    tr[c] = tr[lc] + tr[rc];
}
void add2(int c,int l,int r,int x,int y)
{
    if(l == r)
    {
        ts2[l].insert(y);
        tr[c].mn2 = *ts2[l].begin();
        tr[c].ans = tr[c].mn1 + tr[c].mn2;
        return ;
    }
    if(x <= mid) add2(lc,l,mid,x,y);
    if(x > mid) add2(rc,mid+1,r,x,y);
    tr[c] = tr[lc] + tr[rc];
}
void del1(int c,int l,int r,int x,int y)
{
    if(l == r)
    {
        ts1[l].erase(ts1[l].find(y));
        tr[c].mn1 = *ts1[l].begin();
        tr[c].ans = tr[c].mn1 + tr[c].mn2;
        return ;
    }
    if(x <= mid) del1(lc,l,mid,x,y);
    if(x > mid) del1(rc,mid+1,r,x,y);
    tr[c] = tr[lc] + tr[rc];
}
void del2(int c,int l,int r,int x,int y)
{
    if(l == r)
    {
        ts2[l].erase(ts2[l].find(y));
        tr[c].mn2 = *ts2[l].begin();
        tr[c].ans = tr[c].mn1 + tr[c].mn2;
        return ;
    }
    if(x <= mid) del2(lc,l,mid,x,y);
    if(x > mid) del2(rc,mid+1,r,x,y);
    tr[c] = tr[lc] + tr[rc];
}
void build(int c,int l,int r)
{
    if(l == r)
    {
        ts1[l].insert(INF),ts2[l].insert(INF);
        tr[c].mn1 = *ts1[l].begin();
        tr[c].mn2 = *ts2[l].begin();
        tr[c].ans = tr[c].mn1 + tr[c].mn2;
        return ;
    }
    build(lc,l,mid),build(rc,mid+1,r);
    tr[c] = tr[lc] + tr[rc];
}
int main()
{
    freopen("stone.in","r",stdin);
    freopen("stone.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>Q;
    build(1,1,lim);
    while(Q--)
    {
        int l,r;
        cin>>ch;
        cin>>l>>r;
        if(ch == 'A')
        {
            st1.insert(mkp(-l,r));//l尽可能大,r尽可能小
            st2.insert(mkp(r,-l));//r尽可能小,l尽可能大
            add1(1,1,lim,r,-l);
            add2(1,1,lim,l,r);
        }
        else
        {
            st1.erase(st1.find(mkp(-l,r)));//l尽可能大,r尽可能小
            st2.erase(st2.find(mkp(r,-l)));//r尽可能小,l尽可能大
            del1(1,1,lim,r,-l);
            del2(1,1,lim,l,r);
        }
        auto p1 = *st1.begin(),p2 = *st2.begin();
        if(-p1.fir <= p2.fir) cout<<p2.sec+p1.sec<<"\n";
        else cout<<tr[1].ans<<"\n";
        //cerr<<tr[1].ans<<"\n";
    }
    cerr<<clock()<<"\n";
    return 0;
}